package com.xinxing.learning.batch.file2db.step;

import com.xinxing.learning.batch.common.LogConstants;
import com.xinxing.learning.batch.common.SyncConstants;
import com.xinxing.learning.batch.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.item.ItemProcessor;

@Slf4j
public class File2DbItemProcessor implements ItemProcessor<User, User> {
    @Override
    public User process(User user) throws Exception {
        user.setPhone(checkStr(user.getPhone()));
        user.setTitle(checkStr(user.getTitle()));
        user.setEmail(checkStr(user.getEmail()));
        user.setGender(checkStr(user.getGender()));
        log.info(LogConstants.LOG_TAG + "item process: " + user.getName());
        return user;
    }

    public String checkStr(String dataToCheck) {
        if (SyncConstants.STR_CSV_NULL.equals(dataToCheck)) {
            return null;
        }
        return dataToCheck;
    }
}
